import React, { useEffect } from 'react'
import { useDispatch, useSelector } from "react-redux"
import { incrementAction, decrementAction } from "../../redux/actions/CountAction"
import {updateUserAction} from "../../redux/actions/UserAction"

export default function Sale() {
  const reduxData = useSelector(state => {
    return state
  })
  useEffect(() => {
    console.log("reduxData", reduxData);
  }, [])
  //在组件中调用dispatch派发action
  const dispatch = useDispatch()

  const increment = () => {
    dispatch(incrementAction(5))
  }
  const changeUser = () => {
    dispatch(updateUserAction("王二麻子"))
  }
  return (
    <div>
      <h3>Sale</h3>
      <p>{reduxData.CountRD.count}</p>
      <button onClick={increment}>++</button>
      <p>{JSON.stringify(reduxData.UserRD)}</p>
      <button onClick={changeUser}>修改</button>
    </div>
  )
}
